﻿using MediatR;
using Warehouse.API.Applcation.Command.StorehouseCommand;
using Warehouse.Infrstructre.Interface;

namespace Warehouse.API.Applcation.CommandHandlers.StorehouseCommandHandlers
{
    public class DelStorehouseCommandHandlers:IRequestHandler<DelStorehouseCommand,int>
    {
        private readonly IStorehouseRepository _storehouse;

        public DelStorehouseCommandHandlers(IStorehouseRepository storehouse)
        {
            _storehouse = storehouse;
        }


        public async Task<int> Handle(DelStorehouseCommand request, CancellationToken cancellationToken)
        {
            var list = (await _storehouse.GetAllAsyns()).Where(x=>request.ids.Contains(x.StorehouseId)).ToList();

            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await _storehouse.UpdateAsync(item);
            }
            return 1;
        }
    }
}
